<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/themes/icon.css" />

<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
	$(function(){
		
		//隐藏评论框
		$('#evaluateDiv').window('close');
		//配置搜索框
		$('#searchSname').searchbox({
			searcher : function(value, name) {
				var sname = value;
				$('#orderMsg').datagrid('reload', {
					searchsname : sname
				});
			}
		});
		
		$("#orderMsg").datagrid({
			url: '${pageContext.request.contextPath}/cShowHistoryOrderAction',
			title: '订单列表',
			striped:true,
			nowrap: false,
			columns:[[    
					{field:'checked',checkbox:true,width:100},
			        {field:'oid',title:'订单id',width:100,hidden:true}, 
			        {field:'sname',title:'餐厅名字',width:100},
			        {field:'odishies',title:'订单内容',width:500},
			        {field:'osumprices',title:'订单价格',width:60}, 
			        {field:'ocreatetime',title:'订单创建时间',width:100},
			        {field:'sphone',title:'餐厅电话',width:100},
			        {field:'state',title:'订单状态',width:60},
			        {field:'evaluate',title:'订单评价',width:150},
			]],
			//是否显示分页
			pagination:true,
			toolbar : [{
					iconCls : 'icon-add',
					text : '评价订单',
					handler : function() {
						var order =	$("#orderMsg").datagrid('getSelections');
						if(order.length!=1){
							$.messager.confirm('提示','请选择一条数据',function(){    
								$("#orderMsg").datagrid('clearSelections');
							}); 
						}else{
							if(order[0].state=="已撤销"){
								$.messager.confirm('提示','订单已撤销，不能评论',function(){    
									$("#orderMsg").datagrid('clearSelections');
								});
							}else{
								if(order[0].evaluate!=""){
									$.messager.confirm('提示','不能重复评价',function(){    
										$("#orderMsg").datagrid('clearSelections');
									});
								}else{
									$("#evaluateForm [name=oid]").val(order[0].oid);
									$('#evaluateDiv').window('open');
								}
							}				
						}
					}
				},
				'-',{
					iconCls : 'icon-remove',
					text : '删除订单',
					handler : function() {
						var orders =	$("#orderMsg").datagrid('getSelections');
						if(orders.length<1){
							$.messager.alert('提示','你没有选择');
						}else{
							window.parent.$.messager.confirm('提示','确定要删除吗',function(r){    
							    if (r){    
							    	var oids = new Array();
									var index = 0;
									for (var i = 0; i < orders.length; i++) {
										oids[index++]=orders[i].oid;
									}
									$.ajax({
										type: 'post',
										url: '${pageContext.request.contextPath}/deleteHistoryOrderAction',
										data: {"oids": oids.toString()},
										dataType: 'text',
										success: function(data){
											if(data=="1"){
												$('#orderMsg').datagrid('reload');
												$.messager.show({
													title:'提示',
													msg:'删除成功',
													timeout:2000,
													showType:'slide'
												});
											}else{
												$.messager.show({
													title:'提示',
													msg:'删除失败',
													timeout:2000,
													showType:'slide'
												});
											}
										}
									});    
							    }    
							});
							
						}
					}
				},
			 ],
		});
		
		//配置评论表单信息
		$("#evaluateForm").form({
			url:'${pageContext.request.contextPath}/addEvaluateAction',
			success:function(data){
				if(data=="1"){
					window.parent.$.messager.confirm('提示','评论成功',function(r){    
					    if (r){    
					    	window.location = "${pageContext.request.contextPath}/corder/historyorder.jsp"    
					    }    
					});
				}else{
					window.parent.$.messager.alert('提示','评论失败',"error");
				}
			}
		});
		
	});
	function evaluateForm(){
		$("#evaluateForm").form('submit');
	}
</script>
<body class="container-fluid">
	<input id="searchSname" class="easyui-searchbox"
		data-options="prompt:'输入商家名查询信息',width:150">
	<table id="orderMsg"></table>
	<div id="evaluateDiv" class="easyui-dialog" title="评论" style="width:400px;height:300px;" data-options="modal:true">      
		<form id="evaluateForm" method="post">
	    	<table>
	    		<tr>
	    			<td>评论</td>
	    			<td><input class="easyui-textbox" type="text" name="evaluate" data-options="required:'true'" style="height:100px;width: 200px"></td>
	    		</tr>
	    		<tr style="display: none">
	    			<td>订单id</td>
	    			<td><input class="easyui-textbox" type="text" name="oid"></td>
	    		</tr>
	    	</table>
	    </form>
	    <div style="text-align:center;">
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="evaluateForm()" style="margin-top: 20px">确&nbsp;定</a>
	    </div>
	</div>
</body>
</html>